﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public partial class ExpenseType
    {
        public override string ToString()
        {
            return this.Name;
        }
        public static IQueryable<ExpenseType> GetAll()
        {
            DataAccessDataContext dc = new DataAccessDataContext();

            return from t in dc.ExpenseTypes
                   select t;
        }

        public static ExpenseType Get(Guid id)
        {
            DataAccessDataContext da = new DataAccessDataContext();
            var query = from e in da.ExpenseTypes
                        where e.Id.Equals(id)
                        select e;
            if(query.Count<ExpenseType>() > 0)
                return query.First<ExpenseType>();
            return null;
        }

        public static IQueryable<Template> GetTemplate(Guid id)
        {
            DataAccessDataContext dc = new DataAccessDataContext();
            return from t in dc.ExpenseTypes
                   where t.Id.Equals(id)
                   select t.Template;
        }
    }
}
